//floortrap.txt - A trap blocking a corridor. Booms or is disarmed when used. This
// is the defautl script type of floor trap objects (types 49-52) and should
// not be given to any other object.

//Cell 0 - Difficulty of trap.
//Cell 1 - The effect created.
//  0 - fiery boom (damage is d8)
//  1 - magical boom (damage is d8)
//  2 - spray acid
//  3 - spray poison
//  4 - alarm
//  5 summon
//Cell 2,3 - The sdf which is set to 1 when box is unlocked.
//Cell 4 - The damage of the trap. Should be roughly equal to the level of 
//  the character you want to kill with it. Defaults to 6.

beginobjectscript;

variables;
	short trap_is_gone = 0;
	short got_warning = 0;
	short r1;
	short trap_level = 6;
	
body;

beginstate INIT_STATE;
	if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) {
		if (get_sdf(get_memory_cell(2),get_memory_cell(3)) > 0)
			kill_object(ME,0);
		}
	if ((get_memory_cell(1) == 5) || (get_memory_cell(4) > 0))
		trap_level = get_memory_cell(4);
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE;
	if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) {
		if (get_sdf(get_memory_cell(2),get_memory_cell(3)) > 0)
			kill_object(ME,0);
		}

break;

beginstate USE_STATE;
	if (((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) || (my_current_message() == 106)) {

		if (get_sdf(get_memory_cell(2),get_memory_cell(3)) > 0) {
			print_str("Disarm Trap: The trap has already been neutralized.");
			trap_is_gone = 1;
			kill_object(ME,1);
			end();
			}
		}
		
	if (trap_is_gone == 0) {
		if (get_stat(21) >= get_memory_cell(0)) {
			print_str("Disarm Trap: You are able to disarm it.");
			trap_is_gone = 1;
			kill_object(ME,0);
			broadcast_object_message(3,106);

			if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) {
				if (get_flag(get_memory_cell(2),get_memory_cell(3)) == 0)
					award_party_xp(BASE_TRAP_XP,trap_lev_to_xp_lev(get_memory_cell(0)));
				set_flag(get_memory_cell(2),get_memory_cell(3),1);
				}
			}
			else if (got_warning == 0) {
				print_str("Disarm Trap: You are able to tell that it has a trap, but your");
				print_str("  Mechanics skill isn't high enough to disarm it. Try again to");
				print_str("  proceed anyway.");
				got_warning = 1;
				end();
				}
				else { // trigger trap
					print_str("Disarm Trap: You set off a trap!");
					trap_is_gone = 1;
					kill_object(ME,0);
					if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0))
						set_flag(get_memory_cell(2),get_memory_cell(3),1);
					if (get_memory_cell(1) == 0) { // fire boom
						r1 = get_ran(trap_level,1,8);
						if (trap_level >= 100)
							r1 = r1 + 2000;
							else if (trap_level >= 40)
								r1 = r1 + 400;

						run_sparkles_on_object(ME,173,1,4);
						spray_missiles(51,8,8);
						damage_nearby(r1,5,2,2);
						play_sound(117);
						}
					if (get_memory_cell(1) == 1) { // magic boom
						r1 = get_ran(trap_level,1,8);
						if (trap_level >= 100)
							r1 = r1 + 2000;
							else if (trap_level >= 40)
								r1 = r1 + 400;

						run_sparkles_on_object(ME,162,1,4);
						spray_missiles(54,8,8);
						damage_nearby(r1,5,1,2);
						play_sound(117);
						}
					if (get_memory_cell(1) == 2) { // acid boom
						r1 = get_ran(trap_level,1,8);
						run_sparkles_on_object(ME,12,9,1);
						spray_missiles(52,8,8);
						status_nearby(r1,5,6,2);
						play_sound(177);
						}
					if (get_memory_cell(1) == 3) { // poison boom
						r1 = get_ran(trap_level,1,6);
						run_sparkles_on_object(ME,13,9,1);
						spray_missiles(52,8,8);
						status_nearby(r1,5,6,2);
						play_sound(177);
						}
					if (get_memory_cell(1) == 4) { // alarm
						print_str_color("An alarm goes off! The area is alerted!",1);
						make_zone_hostile();
						play_sound(135);
						}
					if (get_memory_cell(1) == 5) { // summon
						play_sound(136);
						spawn_creature(trap_level);
						run_sparkles_on_object(ME,177,1,4);
						if (get_level(8 + trap_level) > 4) {
							set_boss_level(8 + trap_level,1);
							set_char_status(8 + trap_level,0,8);
							set_char_status(8 + trap_level,8,8);
							}
						place_particle_num(trap_level + 8,10,7,10);
						}
					broadcast_object_message(3,106);
					end();
					}
		}		

break;


beginstate UNLOCK_STATE;
	if (trap_is_gone == 0) {
		print_str("Unlock Spell: An area of the floor nearby glows. It must have a trap.");
		}
break;

